﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>打包发布管理</title>
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <script src="../lib/common/common.js"></script>
</head>
<body>
    <div class="layui-card">
        <table class="layui-table" id="packagTable" lay-filter="packagTable"></table>
    </div>

    <script type="text/html" id="packagbar">
        {{# if(d.fileStatus==1){ }}
        <a title="删除文件" href="javascript:;" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除文件</a>
        {{# } }}
    </script>
    <script type="text/html" id="packagtoolbar">
        <div class="layui-btn-container">
            <form class="layui-form" id="toolbarFrom" lay-filter="toolbarFrom">
                <div class="layui-form-item" style="margin-top:0; margin-bottom:0;">
                    <div class="layui-input-inline layui-show-xs-block">
                        <select name="packagType" id="packagType" lay-filter="packagType" >
                            <option value="1" selected="selected">全流程打包</option>
                            <option value="2">指定文件打包</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <a class="layui-btn" lay-event="packag">打包</a>
                    </div>
                </div>
            </form>
        </div>
    </script>
    <script>
        layui.use(['table','form'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            
            //第一个实例
            $tab = table.render({
                id: 'packagTable',
                elem: '#packagTable',
                skin: 'row',
                url: localStorage.getItem('hosttingaddr') + '/api/Packag/index', //数据接口
                headers: { user: getCookie("userinfo") },
                page: true,
                toolbar: $('#packagtoolbar').html(),
                cols: [[ //表头
                    { field: 'id', title: 'ID', fixed: 'left', align: 'center' },
                    { field: 'userName', title: '打包人', fixed: 'left', align: 'center' },
                    {
                        field: 'createTime', title: '打包时间', align: 'center', templet: function (d) {
                            if (d.createTime != null && d.createTime != "") {
                                return dateFormat("YYYY-mm-dd HH:MM", new Date(d.createTime));
                            }
                        }
                    },
                    {
                        field: 'packagStatus', title: '打包状态', align: 'center', templet: function (d) {
                            if (d.packagStatus == 1) {
                                return "正在打包";
                            }
                            else if (d.packagStatus == 2) {
                                return "打包完成";
                            }
                            else if (d.packagStatus == 3) {
                                return "打包异常";
                            }
                        }
                    },
                    {
                        field: 'fileStatus', title: '文件状态', align: 'center', templet: function (d) {
                            if (d.fileStatus == 1) {
                                return "未删除";
                            }
                            else if (d.fileStatus == 2) {
                                return "已删除";
                            }
                        }
                    },
                    {
                        field: 'fileName', title: '文件名', align: 'center', templet: function (d) {
                            if (d.packagStatus == 2 && d.fileStatus==1) {
                                return "<a href=\"javascript:;\" data-fileName=\"" + d.fileName + "\" onclick=\"downFile(this)\">" + (d.fileName || "") + "</a>"
                            }
                            else {
                                return "";
                            }
                        }
                    },
                    { field: 'remark', title: '打包备注', align: 'center' },
                    { fixed: 'right', title: '操作', align: 'center', toolbar: '#packagbar' }
                ]],
                done: function (res) {
                    form.render('select');
                }
            });
            //监听表工具事件
            table.on('toolbar(packagTable)', function (obj) {
                var event = obj.event;
                switch (event) {
                    case "packag":
                        var packagType = $("#packagType").val();
                        var packagContent = 'processpackag.html';
                        var areaHeight = '600px';
                        if (packagType == "2") {
                            packagContent = 'specifypackag.html';
                            areaHeight = '350px';
                        }

                        layer.open({
                            type: 2,
                            title: '打包发布',
                            maxmin: true,
                            shadeClose: false, //点击遮罩关闭层
                            area: ['600px', areaHeight],
                            content: packagContent,// iframe链接地址
                            end: function () {
                                for (var i = 0; i < 2; i++) {
                                    setTimeout(function () {
                                        table.reload("packagTable");
                                    }, 20000);
                                }
                            }
                        });
                        break;
                    default: break;
                }
            });

            //监听行工具事件
            table.on('tool(packagTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == "delete") {
                    layer.confirm('确认要删除吗？', function (index) {
                        //发异步删除数据
                        layui.$.ajax({
                            type: "post",
                            url: localStorage.getItem('hosttingaddr') + '/api/Packag/deldtefile?id=' + data.id,
                            success: function (data) {
                                layer.msg(data.msg, { icon: 1, time: 1000 });
                                table.reload("packagTable");
                                layer.close(index);
                            }
                        });

                    });
                }
            });
        });
        function downFile(obj) {
            var path = getConfigPath();
            var fileName = layui.$(obj).attr("data-fileName");
            window.open(path + fileName);
        }

        function getConfigPath() {
            //获取当前网址，如： http://localhost:8088/test/test.jsp
            var curPath = window.document.location.href;
            //获取主机地址之后的目录，如： test/test.jsp
            var pathName = window.document.location.pathname;
            var pos = curPath.indexOf(pathName);
            //获取主机地址，如： http://localhost:8088
            var localhostPath = curPath.substring(0, pos);
            var configFloder = "/configfiles/"
            return (localhostPath + configFloder);
        }

    </script>
</body>
</html>